package com.miot.domain.util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;

/**
 * @Author: zhangyanbin
 * @Date: 2019/1/4 16:57
 * @Version 1.0
 */
public class AESUtil {
    // 随机生成密钥
    private static byte[] key = {11,22,33};

    /**
     * 密码AES加密
     *
     * @param password
     * @return
     */
    public static String encryptHex(String password) {
        try {
            // 构建
            AES aes = SecureUtil.aes(key);
            // 加密为16进制表示
            String encryptHex = aes.encryptHex(password);
            return encryptHex;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 密码AES加密
     *
     * @param password
     * @return
     */
    public static String decryptStr(String password) {
        try {
            // 构建
            AES aes = SecureUtil.aes(key);
            // 加密为16进制表示
            String decryptStr = aes.decryptStr(password, CharsetUtil.CHARSET_UTF_8);
            return decryptStr;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
